// 向页面注入JS
function injectCustomJs(jsPath)
{
    jsPath = jsPath || 'js/inject.js';
    var temp = window.document.createElement('script');
    temp.setAttribute('type', 'text/javascript');
    // 获得的地址类似：chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
    temp.src = chrome.extension.getURL(jsPath);
    console.log(temp.src);
    temp.onload = function()
    {
        // 放在页面不好看，执行完后移除掉
        this.parentNode.removeChild(this);
    };
    window.document.head.appendChild(temp);
}

/*在页面加载完才的时候触发的*/
document.addEventListener('DOMContentLoaded', function()
{
    console.log('我被执行了！');
    injectCustomJs();
});

/*这个是backgroud.js发送的消息的*/
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
{
    console.log(window);
    // console.log(sender.tab ?"from a content script:" + sender.tab.url :"from the extension");
    //if(request.cmd == 'test') alert(request.value);
    //
    if(request.cmd == 'test'){
        console.log(window);
    }
    sendResponse('我收到了你的消息！');
});

// window.addEventListener("message", function(e)
// {
//     console.log(e.data);
// }, false);